// 客户拆表
<template>
    <div class="app-container">
        <el-row :gutter="20">
            <!--片区数据-->
            <el-col :span="4" :xs="24">
                <div class="head-container">
                    <el-input v-model="areaName" placeholder="请输入名称" clearable size="small" prefix-icon="el-icon-search"
                        style="margin-bottom: 20px" />
                </div>
                <div class="head-containers">
                    <el-tree :data="areaOptions" :props="defaultProps" :expand-on-click-node="false"
                        :filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current
                        @node-click="handleNodeClick" />
                </div>
            </el-col>

            <!--小区数据-->
            <el-col :span="20" :xs="24">
                <el-card class="box-card">
                    <el-tabs v-model="activeName" @tab-click="handleClick">
                        <el-tab-pane label="已拆表" name="first">
                            <!-- <div>
                                <span>统计时间：</span>
                                <el-date-picker v-model="statisticalTime" type="daterange" align="right" unlink-panels
                                    range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                                    value-format="yyyy-MM-dd HH:mm:ss" @change="stopReportingChange"
                                    :picker-options="pickerOptions">
                                </el-date-picker>
                            </div>
                            <div class="card_box">
                                <div class="card_sty">
                                    <div class="card_left">
                                        <div style="margin-bottom: 10px;">已报停户数</div>
                                        <div>{{ 0 }}(户)</div>
                                    </div>
                                    <div class="card_left">
                                        <img src="../../assets/icons/stopreporting.png" alt="" class="card_img">
                                    </div>
                                </div>
                                <div class="card_sty1">
                                    <div class="card_left1">
                                        <div style="margin-bottom: 10px;">累计操作报停次数</div>
                                        <div>{{ 0 }}(次)</div>
                                    </div>
                                    <div class="card_left1">
                                        <img src="../../assets/icons/number.png" alt="" class="card_img1">
                                    </div>
                                </div>
                            </div> -->
                            <el-form :model="queryParams1" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                                label-width="68px">
                                <el-form-item label="客户名称" prop="customerName">
                                    <el-input v-model="queryParams1.customerName" placeholder="请输入客户名称" clearable
                                        style="width: 150px" />
                                </el-form-item>
                                <el-form-item label="客户编码" prop="customerCode">
                                    <el-input v-model="queryParams1.customerCode" placeholder="请输入客户编码" clearable
                                        style="width: 150px" />
                                </el-form-item>
                                <el-form-item label="操作人" prop="telephone">
                                    <el-input v-model="queryParams1.telephone" placeholder="请输入操作人" clearable
                                        style="width: 150px" />
                                </el-form-item>
                                <el-form-item>
                                    <el-button type="primary" icon="el-icon-search" size="mini"
                                        @click="handleQuery">搜索</el-button>
                                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                                </el-form-item>
                            </el-form>

                            <el-table v-loading="loading" :data="userList1" border>
                                <el-table-column label="客户名称" align="center" key="customerName" prop="customerName"
                                    :show-overflow-tooltip="true" />
                                <el-table-column prop="status" label="客户类型" width="80">
                                    <template slot-scope="scope">
                                        <dict-tag :options="dict.type.customer_type" :value="scope.row.customerType" />
                                    </template>
                                </el-table-column>
                                <el-table-column label="客户编码" align="center" key="customerCode" prop="customerCode"
                                    :show-overflow-tooltip="true" width="100" />
                                <el-table-column label="客户地址" align="center" key="customerAddress" prop="customerAddress"
                                    :show-overflow-tooltip="true" />
                                <el-table-column label="联系电话" align="center" key="telephone" prop="telephone"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="表通讯地址" align="center" key="customerAddress" prop="customerAddress"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="停用原因" align="center" key="remark" prop="remark"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="操作时间" align="center" key="updateTime" prop="updateTime"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="账户余额" align="center" key="remainAmout" prop="remainAmout"
                                    :show-overflow-tooltip="true" width="120" />
                                <!--<el-table-column label="账户余额" align="center" key="telephone5" prop="telephone5"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="备注" align="center" key="remark" prop="remark"
                                    :show-overflow-tooltip="true" />-->
                                <!-- <el-table-column label="操作" align="center" width="200"
                                    class-name="small-padding fixed-width" fixed="right">
                                    <template slot-scope="scope">
                                        <el-button size="mini" type="text" icon="el-icon-edit"
                                            @click="handleUpdate(scope.row)"
                                            v-hasPermi="['fileManagement:civilArchives:edit']">修改</el-button>
                                        <el-button size="mini" type="text" icon="el-icon-view"
                                            @click="handleDelete(scope.row)"
                                            v-hasPermi="['fileManagement:civilArchives:remove']">查看</el-button>
                                    </template>
                                </el-table-column> -->
                            </el-table>

                            <pagination v-show="total1 > 0" :total="total1" :page.sync="queryParams1.pageNum"
                                :limit.sync="queryParams1.pageSize" @pagination="getList1" />
                        </el-tab-pane>
                        <el-tab-pane label="客户档案" name="second">
                            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                                label-width="68px">
                                <el-form-item label="客户类型" prop="customerType">
                                    <el-select v-model="queryParams.customerType" filterable placeholder="请选择">
                                        <el-option v-for="dict in dict.type.customer_type" :key="dict.value"
                                            :label="dict.label" :value="dict.value" />
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="客户名称" prop="customerName">
                                    <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable
                                        style="width: 150px" />
                                </el-form-item>
                                <el-form-item label="客户编码" prop="customerCode">
                                    <el-input v-model="queryParams.customerCode" placeholder="请输入客户编码" clearable
                                        style="width: 150px" />
                                </el-form-item>
                                <el-form-item label="手机号" prop="telephone">
                                    <el-input v-model="queryParams.telephone" placeholder="请输入手机号" clearable
                                        style="width: 150px" />
                                </el-form-item>
                                <el-form-item>
                                    <el-button type="primary" icon="el-icon-search" size="mini"
                                        @click="handleQuery">搜索</el-button>
                                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                                </el-form-item>
                            </el-form>

                            <el-table v-loading="loading" :data="userList" border>
                                <el-table-column label="客户名称" align="center" key="customerName" prop="customerName"
                                    :show-overflow-tooltip="true" />
                                <el-table-column prop="status" label="客户类型" width="80">
                                    <template slot-scope="scope">
                                        <dict-tag :options="dict.type.customer_type" :value="scope.row.customerType" />
                                    </template>
                                </el-table-column>
                                <el-table-column label="客户编码" align="center" key="customerCode" prop="customerCode"
                                    :show-overflow-tooltip="true" width="100" />
                                <el-table-column label="总购气金额" align="center" key="totalAmout" prop="totalAmout"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="余额" align="center" key="remainAmout" prop="remainAmout"
                                    :show-overflow-tooltip="true" width="100" />

                                <el-table-column label="总用气量" align="center" key="totalVolume" prop="totalVolume"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="剩余气量" align="center" key="remainVolume" prop="remainVolume"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="计费周期开始时间" align="center" key="cycleStartTime" prop="cycleStartTime"
                                    :show-overflow-tooltip="true" width="150" />
                                <el-table-column label="计费周期结束时间" align="center" key="cycleEndTime" prop="cycleEndTime"
                                    :show-overflow-tooltip="true" width="150" />
                                <el-table-column label="周期内总用气量" align="center" key="cycleUseGas" prop="cycleUseGas"
                                    :show-overflow-tooltip="true" width="150" />
                                <el-table-column label="周期内总使用金额" align="center" key="cycleUseAmount" prop="cycleUseAmount"
                                    :show-overflow-tooltip="true" width="150" />
                                <el-table-column label="充值次数" align="center" key="payCount" prop="payCount"
                                    :show-overflow-tooltip="true" />
                                <el-table-column label="客户地址" align="center" key="customerAddress" prop="customerAddress"
                                    :show-overflow-tooltip="true" />
                                <el-table-column label="联系电话" align="center" key="telephone" prop="telephone"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="表通讯地址" align="center" key="telephone0" prop="telephone0"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="运行状态" align="center" key="telephone9" prop="telephone9"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="账户余额" align="center" key="telephone8" prop="telephone8"
                                    :show-overflow-tooltip="true" width="120" />
                                <el-table-column label="备注" align="center" key="remark" prop="remark"
                                    :show-overflow-tooltip="true" />
                                <el-table-column label="操作" align="center" width="200"
                                    class-name="small-padding fixed-width" fixed="right">
                                    <template slot-scope="scope">
                                        <el-button size="mini" type="text" icon="el-icon-edit"
                                            @click="handleUpdate(scope.row)"
                                            v-hasPermi="['system:maintenancerecord:dismantle']">拆表</el-button>
                                        <!-- <el-button size="mini" type="text" icon="el-icon-view"
                                            @click="handleDelete(scope.row)"
                                            v-hasPermi="['fileManagement:civilArchives:remove']">查看</el-button> -->
                                    </template>
                                </el-table-column>
                            </el-table>

                            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                                :limit.sync="queryParams.pageSize" @pagination="getList" />
                        </el-tab-pane>
                    </el-tabs>

                </el-card>

            </el-col>
        </el-row>
        <InforValue v-if="infoStaus" @closeDilog="closeDilog" :info="childInfo" />
        <!-- 添加或修改小区配置对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                <el-form-item label="拆表原因" prop="remark">
                    <el-input type="textarea" :rows="2" placeholder="请输入拆表原因" v-model="form.remark">
                    </el-input>
                </el-form-item>
                <el-form-item label="附件" prop="files">
                    <el-upload class="upload-demo" :action="fileUrl" :on-success="handleSuccess" :file-list="fileList">
                        <el-button size="small" type="primary">点击上传</el-button>
                        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                    </el-upload>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { areaList, areaTreeList } from "@/api/fileManagement/areainfo.js"
import { customeList, customeInfo, addCustome, updateArea, delCustome, exportCustome, generateNumber, customeStatusList, dismantleCustome } from "@/api/fileManagement/civilArchives.js"
import { listGasmeter, } from "@/api/systemSetup/gasMeter.js";
import { getToken } from "@/utils/auth";
import { listSupplier, } from "@/api/system/supplierInfo.js";
import { addMeterarchives, } from "@/api/fileManagement/meterarchives.js"
import { planSelectList, } from '@/api/service/planlist.js'
import Treeselect from '@riophae/vue-treeselect'
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import InforValue from './info.vue'

export default {
    name: "civilArchives",
    components: { Treeselect, InforValue },
    dicts: ["customer_type"],
    data() {
        return {
            fileUrl: process.env.VUE_APP_BASE_API + "/upload",
            childInfo: {},
            infoStaus: false, // 详情弹框
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            statisticalTime: '', // 统计时间
            activeName: 'second',
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            idName: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            total1: 0,
            // 小区表格数据
            userList: null,
            userList1: null,
            // 弹出层标题
            title: "",
            //表计弹出层标题
            title2: "",
            // 片区树选项
            areaOptions: undefined,
            // 是否显示弹出层
            open: false,
            // 片区名称
            areaName: '',
            //是否表计显示弹出层
            bjOPen: false,
            // 表单参数
            form: {},
            form1: {},
            defaultProps: {
                children: "children",
                label: "label",
            },
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                customerType: null,
                customerName: null,
                idNumber: null,
                deptId: null,
                openDate: null,
                telephone: null,
                customerCode: null,
                serviceType: 1,
                serviceStatus: 0
            },
            queryParams1: {
                pageNum: 1,
                pageSize: 10,
                customerType: null,
                customerName: null,
                idNumber: null,
                deptId: null,
                openDate: null,
                telephone: null,
                customerCode: null,
                serviceType: 1,
                serviceStatus: 1
            },
            // 表单校验
            rules: {
                remark: [
                    { required: true, message: "原因不能为空", trigger: "blur" },
                ],
            },
            activeNames: ["1"],
            treeList: [],
            meterList: [],
            supplierList: [],
            schemeList: [],
            customStaus: false,
            areID: null,
            custerId: '',
            fileList: [],
        };
    },
    watch: {
        // 根据名称筛选企业树
        areaName(val) {
            this.$refs.tree.filter(val);
        },
        form: {
            deep: true,
            handler(val) {
                this.form = val
            },
        },
        form1: {
            deep: true,
            handler(val) {
                this.form1 = val
            },
        }
    },
    created() {
        this.getList();
        this.getDeptTree();
        this.getTreeList()
    },
    methods: {
        // 附件上传成功
        handleSuccess(response, file, fileList) {
            if (response.code === 200) {
                this.$set(this.form, 'files', response.imgUrl)
            }
        },
        // 统计时间改变
        stopReportingChange(event) {
            console.log(event)
        },
        // tab切换
        handleClick(tab, event) {
            console.log(tab, event);
            if (tab.name == 'first') {
                this.getList1()
            } else {
                this.getList()
            }
        },
        // 查询计价方案
        getPricingPlanList() {
            planSelectList().then((res) => {
                this.schemeList = res
            })
        },
        // 表计类型
        getmeterList() {
            this.loading = true;
            listGasmeter().then((response) => {
                this.meterList = response.rows;
                this.loading = false;
            });
        },
        /** 查询供应商列表 */
        getsupplierList() {
            let params = {
                pageNum: 1,
                pageSize: 9999,

            }
            this.loading = true;
            listSupplier(params).then((response) => {
                this.supplierList = response.rows;

            });
        },
        /** 获取新增小区 **/
        getTreeList() {
            let param = {
                id: null
            }
            if (!this.customStaus) {
                param.id = this.areID
            } else {
                param.id = null
            }
            areaList(param).then((response) => {
                this.treeList = response.rows;
            });
        },
        /** 查询企业下拉树结构 */
        getDeptTree() {
            areaTreeList().then((response) => {
                this.areaOptions = response.data;
            });
        },
        // 树查询
        treeBlur(event) {
            console.log(event)
        },


        getList() {
            this.loading = true;
            customeStatusList(this.queryParams).then((response) => {
                this.userList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        getList1() {
            this.loading = true;
            customeStatusList(this.queryParams1).then((response) => {
                this.userList1 = response.rows;
                this.total1 = response.total;
                this.loading = false;
            });
        },

        // 筛选节点
        filterNode(value, data) {
            console.log(data)
            if (!value) return true;
            return data.label.indexOf(value) !== -1;
        },
        // 节点单击事件
        handleNodeClick(data) {
            this.queryParams.areaId = data.id;
            if (data.type === '2') {
                this.customStaus = true
            } else {
                this.customStaus = false
            }
            this.handleQuery();

            this.areID = data.id
            console.log(this.form.areaId, 111111111, typeof this.form.areaId,)
            console.log(this.treeList, 111111111)
            this.getTreeList()
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表计取消按钮
        cancel2() {
            this.bjOPen = false;
        },
        // 表单重置
        reset() {
            this.form = {
                remark: undefined,
                files: undefined,
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.queryParams.areaId = undefined;
            this.$refs.tree.setCurrentKey(null);
            this.handleQuery();
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.getNumber()
            this.title = "添加民用档案";
            if (this.customStaus) {
                this.form.areaId = this.areID
            } else {
                this.form.areaId = null
            }
        },
        // 刷新客户编码
        refreshNumber() {
            this.getNumber()
        },
        // 获取客户编码
        getNumber() {
            generateNumber('21').then((res) => {
                // this.form.customerCode = res.data
                this.$set(this.form, 'customerCode', res.data)
            })
        },
        // 刷新表计编码
        refreshNumber1() {
            this.getNumber1()
        },
        // 获取表计编码
        getNumber1() {
            generateNumber('22').then((res) => {
                // this.form.customerCode = res.data
                this.$set(this.form1, 'meterCode', res.data)
            })
        },

        /** 修改按钮操作 */
        handleUpdate(row) {
            this.title = "拆表";
            this.reset();
            this.custerId = row.id;
            this.open = true;
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    let param = {
                        customerId: this.custerId,
                        remark: this.form.remark,
                        files: this.form.files
                    }
                    dismantleCustome(param).then((res) => {
                        if (res.code == 200) {
                            this.open = false
                            this.$modal.msgSuccess("拆表成功");
                            this.getList()
                        } else {
                            this.open = false
                            this.$modal.msgError(res.msg);
                        }
                    })
                }
            });
        },
        /** 查看详情按钮操作 */
        handleDelete(row) {
            this.infoStaus = true
            this.childInfo = row
        },
        closeDilog() {
            this.infoStaus = false
        },

        // 提交上传文件
        submitFileForm() {
            this.$refs.upload.submit();
        },
    },
};
</script>
<style lang="scss">
.head-containers {
    width: 200px;
    overflow: auto;

    .el-tree {
        min-width: 100%;
        display: inline-block !important;
    }
}

.el-form-item--medium .el-form-item__content {
    line-height: 34px !important;
}

.el-form-item--medium .el-form-item__label {
    line-height: 37px !important;
}

.card_box {
    width: 100%;
    height: 160px;
    display: flex;
    justify-content: flex-start;
    margin-top: 15px;
    margin-bottom: 15px;
}

.card_sty {
    width: 30%;
    height: 160px;
    background: linear-gradient(135deg, #fdfafa, #ffead6);
    border-radius: 10px;
    margin-right: 10px;
    display: flex;
    justify-content: space-between;
    border: 1px solid #ebeef5;
}

.card_sty1 {
    width: 30%;
    height: 160px;
    background: linear-gradient(135deg, #fff, #edfafc);
    border-radius: 10px;
    margin-right: 10px;
    display: flex;
    justify-content: space-between;
    margin-left: 20px;
    border: 1px solid #ebeef5;
}

.card_left1 {
    width: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgb(26, 204, 238)
}

.card_left {
    width: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgb(255, 103, 0);
}

.card_img {
    display: inline-block;
    width: 50px;
    height: 60px;
}

.card_img1 {
    display: inline-block;
    width: 60px;
    height: 60px;
}
</style>